# 给定一个列表根据grade来排序
from pprint import pprint
classes = [
    {"name": "N_1", "age": 21, "grade": "A"},
    {"name": "N_5", "age": 27, "grade": "A"},
    {"name": "N_4", "age": 19, "grade": "C"},
    {"name": "N_2", "age": 21, "grade": "D"},
    {"name": "N_3", "age": 22, "grade": "A"},
    {"name": "N_6", "age": 24, "grade": "B"},
]
classes.sort(key=lambda x: x["grade"])
pprint(classes)


# 通过filter语句筛选出a的同学
f = filter(lambda x: True if x["grade"] == "A" else False, classes)
pprint(list(f))


# 通过map函数将上述同学age加1
def my_function_1(a):
    a["age"] += 1
    return a
m = map(my_function_1, classes)
pprint(list(m))


# 使用递归重构斐波那契函数
def feibo(n):
    if n == 0:
        return n
    elif n == 1:
        return n
    else:
        return feibo(n - 1) + feibo(n - 2)
for i in range(12):
    print(feibo(i))